<!DOCTYPE html>
<html>
<head>
    <include file="Public:header" />
    <!-- jqgrid-->
    <link href="__ACSS__/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox ">
                    <div class="ibox-content">
                    	<div class="ibox-search-box">
                    		<div class="row">
	                    		<div class="infont col-md-2">
		                    		<input type="text" name="username" class="form-control" placeholder="用户名">
								</div>
								<div class="infont col-md-2">
		                    		<input type="text" name="zfb_email" class="form-control" placeholder="支付宝账号">
								</div>
								<div class="infont col-md-2">
		                    		<select name="has_refund" class="form-control" placeholder="提现状态">
		                    			<option value="">请选择</option>
		                    			<option value="-1">提现失败</option>
										<option value="1">申请提现中</option>
										<option value="2">提现完成</option>
									</select>
								</div>
	                    		<div class="infont col-md-2">
	                    			<button class="btn btn-success btn-block btn-ibox-search" type="button">搜索</button>
	                    		</div>
                    		</div>
                    	</div>
                        <div class="jqGrid_wrapper">
                            <table id="table_list"></table>
                            <div id="pager_list"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<!-- 全局js -->
<include file="Public:foot" />
<!-- jqGrid -->
<script src="__AJSPLUGINS__/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="__AJSPLUGINS__/jqgrid/jquery.jqGrid.min.js?0820"></script>
<!-- Page-Level Scripts -->
<script>
$(document).ready(function () {
	var params = "?";
	if($(":input[name=username]").length > 0) {
		params += "&";
		params += "username" + "=" + $(":input[name=username]").val();
	}
	if($(":input[name=zfb_email]").length > 0) {
		params += "&";
		params += "zfb_email" + "=" + $(":input[name=zfb_email]").val();
	}
	if($(":input[name=has_refund]").length > 0) {
		params += "&";
		if($(":input[name=has_refund]").val() == "0") {
			var ids = "";
			$(":input[name=has_refund]").find("option").each(function() {
				if(ids != "") {
					ids += ",";
				}
				ids += $(this).val();
			})
			params += "has_refund" + "=" + ids;
		}else{
			params += "has_refund" + "=" + $(":input[name=has_refund]").val();
		}
	}
	//初始化
    $.jgrid.defaults.styleUI = 'Bootstrap';
    $("#table_list").jqGrid({
    	url : '__URL__/getAllData' + params,
        datatype: "json",
        height: 520,
        autowidth: true,
        shrinkToFit: true,
        rowNum: 15,
        rowList: [10, 15, 30, 50],
        colNames : [ 'ID', '用户名', '提现金额', '提现时间', '支付宝姓名', '支付宝账号', '打款时间', '提现状态' ], 
        colModel : [ {name : 'id',index : 'id'},
                     {name : 'username',index : 'username', sortable: false},
                     {name : 'detail_price',index : 'detail_price'},
                     {name : 'refund_time',index : 'refund_time',formatter: 'date',formatoptions: {srcformat:'u',newformat:'Y-m-d H:i:s'}},
                     {name : 'zfb_name',index : 'zfb_name'},
                     {name : 'zfb_email',index : 'zfb_email'},
                     {name : 'refund_done_time',index : 'refund_done_time',sortable : false,formatter : function(cellvalue, options, rowObject){
                    	 if(cellvalue != 0) {
                    		 content = new Date(parseInt(cellvalue) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
                    	 }else{
                    		 content = 0;
                    	 }
                    	 return content;
                	 }},
                	 <if condition="$is_finance eq 1">
	                	 {name : 'has_refund',index : 'has_refund',sortable : false,formatter : function(cellvalue, options, rowObject){
	                    	 if(cellvalue == 1) {
	                    		 content = '';
	                    		 content += '<button class="btn btn-white btn-xs btn-outline" onclick="updateStatus('+ rowObject.id +','+ 2 +')">完成提现</button>';
	                    		 content += ' <button class="btn btn-white btn-xs btn-outline" onclick="updateStatus('+ rowObject.id +','+ -1 +')">拒绝提现</button>';
	                    	 }else if(cellvalue == 2) {
	                    		 content = '提现已处理';
	                    	 }else if(cellvalue == -1) {
	                    		 content = '提现失败';
	                    	 }
	                    	 return content;
	                	 }},
                	 <elseif condition="$is_finance eq 2"/>
	                	 {name : 'has_refund',index : 'has_refund',sortable : false,formatter : function(cellvalue, options, rowObject){
	                    	 if(cellvalue == 1) {
	                    		 content = '申请提现中';
	                    	 }else if(cellvalue == 2) {
	                    		 content = '提现已处理';
	                    	 }else if(cellvalue == -1) {
	                    		 content = '提现失败';
	                    	 }
	                    	 return content;
	                	 }},
                	 </if>
                     
                   ],
        pager: "#pager_list",
        viewrecords: true,
        hidegrid: false
    });
    
    //搜索
    $(".btn-ibox-search").click(function() {
    	result = getSearchParamByInput();
    	$("#table_list").jqGrid('setGridParam', {
    		page: 1,
    		url : '__URL__/getAllData' + result
    	}).trigger("reloadGrid");
    })
    //监控回车
    $(".ibox-search-box").find(":input").keydown(function(event) {
		if(event.keyCode == 13){
			$(".btn-ibox-search").trigger("click");
		}
	})
    
    //获取搜索条件（仅限封装简单条件）
    function getSearchParamByInput() {
    	var result = "";
    	$(".ibox-search-box").find(":input").each(function() {
    		if($(this).val() != "") {
    			if(result != "") {
    				result += "&";
    			}else{
    				result += "?";
    			}
    			result += $(this).attr("name") + "=" + $(this).val();
    		}
    	})
    	return result;
    }
    
 	// 设置按钮
    $("#table_list").jqGrid('navGrid', '#pager_list', {
        edit: false,
        add: false,
        del: false,
        search: false
    }, {
        height: 200,
        reloadAfterSubmit: true
    });
    // 添加适配响应
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list').setGridWidth(width);
    });
    
});

//完成提现
function updateStatus(id,islock) {
	layer.confirm('确定执行？', function(index){
    	var index = layer.load(2);
    	if(islock == 2) {
    		$.ajax({
    			url:"__URL__/completeWithdraw",
    			type:"post",
    			data:{'id':id,'field':'has_refund','islock':islock},
    			success:function(json){
    				var data = eval("("+json+")");
    				if(data.status == 1){
    					layer.msg(data.info);
    					$('#table_list').trigger("reloadGrid");
    				}else{
    					layer.msg(data.info);
    				}
    				layer.close(index);
    			}
    		})
    	}else if(islock == -1) {
    		$.ajax({
    			url:"__URL__/refusalWithdraw",
    			type:"post",
    			data:{'id':id,'field':'has_refund','islock':islock},
    			success:function(json){
    				var data = eval("("+json+")");
    				if(data.status == 1){
    					layer.msg(data.info);
    					$('#table_list').trigger("reloadGrid");
    				}else{
    					layer.msg(data.info);
    				}
    				layer.close(index);
    			}
    		})
    	}
	});
}
</script>
</html>